﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using PlanningGIS.Framework;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;

namespace PlanningGIS.TocContextMenu.Button
{
    /// <summary>
    /// 作用：TOC右键菜单缩放至图层按钮类
    /// </summary>
    public class ZoomToLayer : BaseCommand 
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public ZoomToLayer()
        {
            base.m_caption = "缩放至图层";
            base.m_toolTip = base.Caption;
        }

        /// <summary>
        /// 应用程序
        /// </summary>
        IApplication _Application = null;

        /// <summary>
        /// 创建按钮
        /// </summary>
        /// <param name="hook"></param>
        public override void OnCreate(object hook)
        {
            if (_Application == null)
                _Application = hook as IApplication;
        }

        /// <summary>
        /// 点击事件
        /// </summary>
        public override void OnClick()
        {
            if (_Application == null) return;
            if (!((_Application as IFramework).TOCControl.CustomProperty is ILayer)) return;
            ILayer pLayer = (_Application as IFramework).TOCControl.CustomProperty as ILayer;
            (_Application as IFramework).MapControl.Extent = pLayer.AreaOfInterest;
            (_Application as IFramework).MapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
        }

        /// <summary>
        /// 图标
        /// </summary>
        public override int Bitmap
        {
            get
            {
                string bitmapResourceName = "PlanningGIS.TocContextMenu.Res." + this.GetType().Name + ".ico";
                System.IO.Stream stream = GetType().Assembly.GetManifestResourceStream(bitmapResourceName);
                if (stream == null) return 0;
                return new Bitmap(stream).GetHbitmap().ToInt32();
            }
        }
    }
    
}
